<template>
	<view>
		<view class="top">
			<view class="padding-lg flex-row align-center">
				<u-avatar :src="userinfo.portrait" size="80"></u-avatar>
				<view class="flex-col justify-between info">
					<view class="name text-cut flex-row align-center">{{userinfo.nickname}}
						<image class="vip-icon margin-left-sm" :class="{ active: userinfo.level>1 }" src="../../static/images/vip.png" mode=""></image>
					</view>
					<view class="date text-cut">{{myLevelText}}</view>
				</view>
			</view>
		</view>

		<view class="main" v-if="level">
			<swiper class="swiper" :indicator-dots="true" :current="current" :autoplay="false" :interval="3000" :duration="1000"
			 indicator-color="#ffffff" indicator-active-color="#e5bb72" @change="swiperChange">
				<swiper-item v-for="(i,k) in level" :key="i.id">
					<view class="vip-card" :class="'vip' + k">
						<view class="flex-row justify-between">
							<view>
								<view class="text-2em">
									{{i.level_name}}
								</view>
								<view class="margin-tb-xs">
									{{userinfo.level_expire_at ? userinfo.level_expire_at + '到期' : ''}}
								</view>
							</view>
							<view class="text-2em margin-tb-xs" v-if="i.level_price">
								￥{{i.level_price}}
							</view>
						</view>

						<view class="flex-row justify-between">
							<view class="icons flex-row align-center">
								<view style="max-width: 200rpx;height: 50rpx;overflow: hidden;">
									<image class="icon" :src="j.right_icon" mode="" v-for="j in i.right" :key="j.id"></image>
								</view>
								<view class="text-white">享{{i.right.length}}项特权</view>
							</view>
							<view class="btn" v-if="i.level_price" @click="$goto('/pages/mine/vip-pay?id=' + i.id)">
								开通会员
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>


			<view class="padding">
				<view class="content">
					<view class="title">
						尊享权益
					</view>

					<u-gap height="32"></u-gap>

					<view class="pro" v-for="i in currentLevel" :key="i.id">
						<image class="icon" :src="i.right_icon" mode="widthFix"></image>
						<view class="flex-col justify-around">
							<view class="text-black">{{i.right_title}}</view>
							<view class="text-gray">{{i.right_desc}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import store from '../../utils/store.js'
	export default {
		data() {
			return {
				prolist: [{
					id: 1
				}],
				level: [],
				current: 0
			};
		},
		computed: {
			userinfo() {
				return store.state.userinfo
			},
			myLevel() {
				return store.state.userinfo.level - 1
			},
			myLevelText() {
				let levels = ['普通用户', '超级会员', '企业会员']
				return levels[store.state.userinfo.level - 1]
			},
			currentLevel() {
				return this.level[this.current]?.right
			}
		},
		onShow() {
			this.getList()
		},
		onPullDownRefresh() {
			this.getList()
		},
		methods: {
			async getList() {
				let res = await this.$u.get('/level/list')
				let {
					level
				} = res.data.result
				this.level = level
				this.current = this.myLevel
				uni.stopPullDownRefresh()
			},
			swiperChange(e) {
				this.current = e.detail.current
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #f5f6f7;
	}

	.top {
		background: #1e1f25;
		height: 360rpx;
		color: #fff;

		.info {
			padding-left: 24rpx;
			height: 80rpx;
			letter-spacing: 1px;
		}

		.name {
			font-size: 32rpx;
		}

		.date {
			font-size: 24rpx;
			color: #C3C6CD;
		}
	}

	.main {
		margin-top: -64rpx;
		min-height: 64rpx;
		border-radius: 26rpx 26rpx 0 0;
		background: #f5f6f7;

		.content {
			margin-top: -120rpx;
			padding: 32rpx;
			background: #fff;
			border-radius: 16rpx;
		}

		.title {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #424242;
		}
	}

	.pro {
		display: flex;
		align-items: center;
		margin-bottom: 24rpx;

		.icon {
			width: 64rpx;
			height: 64rpx;
			margin-right: 24rpx;
		}

		.flex-col {
			min-height: 90rpx;
			width: 500rpx;
		}
	}

	.swiper {
		transform: translateY(-120rpx);
		height: 340rpx;

		/deep/ .uni-swiper-dots {
			transform: translate(-50%, 100%);
		}

		/deep/ .uni-swiper-dot {
			width: 24rpx;
			height: 8rpx;
			border-radius: 4rpx;
		}
	}

	.vip-card {
		margin: 0 auto;
		padding: 32rpx;
		width: 700rpx;
		height: 280rpx;
		border-radius: 24rpx;
		background: #534d4d;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		font-size: 24rpx;
		color: #d5a473;
		letter-spacing: 1px;

		&.vip0 {
			background: url('http://v2.qidka.com/storage/vcard/vip0.png') center / cover;
			color: #1E1F25;
		}

		&.vip1 {
			background: url('http://v2.qidka.com/storage/vcard/vip1.png') center / cover;
			color: #3A1D0C;
		}

		&.vip2 {
			background: url('http://v2.qidka.com/storage/vcard/vip2.png') center / cover;
		}

		.icon {
			width: 50rpx;
			height: 50rpx;
			margin-right: 16rpx;
		}

		.btn {
			width: 160rpx;
			height: 52rpx;
			background: linear-gradient(0deg, #D19C69, #EAD2AF);
			border-radius: 26rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 24rpx;
			color: #000;
			font-weight: bold;
		}
	}

	.vip-icon {
		width: 105rpx;
		height: 35rpx;
		filter: grayscale(1);

		&.active {
			filter: grayscale(0);
		}
	}
</style>
